import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;

import javax.swing.ButtonModel;
import javax.swing.JButton;


@SuppressWarnings("serial")
public class RedButton extends JButton {
	
	private Color startColor = new Color(216, 74, 56);
	private Color endColor = new Color(216, 74, 56);
	private Color rollOverColor = new Color(223, 83, 65);
	private Color pressedColor = new Color(208, 60, 41);
	private int outerRoundRectSize = 10;
	private int innerRoundRectSize = 8;
	private GradientPaint GP;
	private Color border = new Color(195, 39, 19);

	public RedButton(String text, int fontSize) {
		super();
		setText(text);
		setContentAreaFilled(false);
		setBorderPainted(false);

		
		setFont(new Font("Arial", Font.BOLD, fontSize));
		setFocusable(false);

	}

	public RedButton(Color startColor, Color endColor,
			Color rollOverColor, Color pressedColor) {
		super();
		this.startColor = startColor;
		this.endColor = endColor;
		this.rollOverColor = rollOverColor;
		this.pressedColor = pressedColor;
		setForeground(Color.WHITE);
		setFocusable(false);
		setContentAreaFilled(false);
		setBorderPainted(false);

	}
	

		public void paintComponent(Graphics g) {
		Graphics2D g2d = (Graphics2D) g.create();
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		int h = getHeight();
		int w = getWidth();
		ButtonModel model = getModel();
		
		if (!model.isEnabled()) {
			setForeground(Color.GRAY);
			GP = new GradientPaint(0, 0, new Color(216, 74, 56), 0, h, new Color(216, 74, 56),
					true);
			border = new Color(217, 66, 47);
		} else {
			setForeground(Color.white);
			if (model.isRollover()) {
				GP = new GradientPaint(0, 0, rollOverColor, 0, h, rollOverColor,
						true);
	    	} else {
				GP = new GradientPaint(0, 0, startColor, 0, h, endColor, true);
			}
		}
		
		g2d.setPaint(GP);
		if (model.isPressed()) {
			GP = new GradientPaint(0, 0, pressedColor, 0, h, pressedColor, true);
			g2d.setPaint(GP);

		} else {
			GP = new GradientPaint(0, 0, startColor, 0, h, endColor, true);
		}
		
		
		RoundRectangle2D.Float r2d = new RoundRectangle2D.Float(0, 0, w - 1,
				h - 1, 10, 10);
		Shape clip = g2d.getClip();
		g2d.clip(r2d);
		g2d.fillRect(0, 0, w, h);
		g2d.setClip(clip);
		g2d.drawRoundRect(1, 1, w - 3, h - 3, innerRoundRectSize,
				innerRoundRectSize);
		g2d.setPaint(border);
		g2d.drawRoundRect(0, 0, w - 1, h - 1, outerRoundRectSize,
				outerRoundRectSize);
		g2d.setPaint(new Color(48, 121, 237));
		
		g2d.dispose();

		super.paintComponent(g);
	}

	//Boja pozadine
	public void setStartColor(Color color) {
		startColor = color;
	}

	//Pritisnuta boja
	public void setEndColor(Color pressedColor) {
		endColor = pressedColor;
	}

	//Pocetna boja (gradijent, ako se bude trebao implementirat)
	public Color getStartColor() {
		return startColor;
	}

	//Zavsna boja (gradijent, ako se bude trebao implementirat)
	public Color getEndColor() {
		return endColor;
	}
}